package com.genebio.equinox.update.servlets;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.core.runtime.IProgressMonitor;

import com.genebio.equinox.update.Search;

public class SearchFeatures extends HttpServlet {
	private Search search;

	@Override
	public void init(ServletConfig config) throws ServletException {
		search=new Search("http://downloads.phenyx-ms.com/daemon/submit/");
	}
	
	@Override
	protected void doGet(HttpServletRequest req, final HttpServletResponse resp)
			throws ServletException, IOException {
		search.setPrintStream(resp.getWriter());
		resp.getWriter().println("<pre>");
		search.run(new IProgressMonitor(){
			public void beginTask(String name, int totalWork) {
				try {
					resp.getWriter().println(name);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			public void done() {
			}

			public void internalWorked(double work) {
			}

			public boolean isCanceled() {
				return false;
			}

			public void setCanceled(boolean value) {
			}

			public void setTaskName(String name) {
			}

			public void subTask(String name) {
			}

			public void worked(int work) {
			}
			
		});
		resp.getWriter().println("</pre>");
		
	}
}
